package com.example.app.pages.main.home.addNew.addRecord

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Save
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.example.app.addNewViewModel
import com.example.app.addRecordViewModel
import com.example.app.components.MySpacer.MySpacer
import com.example.app.mainViewModel
import com.example.app.pages.main.home.addNew.addRecord.viewModel.AddRecordViewModel
import com.example.app.pages.main.home.me.viewModel.AddNewViewModel
import com.example.app.viewmodel.MainViewModel
import kotlinx.coroutines.launch

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun IncomeContent(
    placeClick: () -> Unit,
    topbarAndStatusBarHeight: Int,
) {
    var colScroll = rememberScrollState()
    var imePaddingBottomValue = mainViewModel.imePaddingBottomValue.collectAsState()
    var scope = rememberCoroutineScope()
    var remarkinputFocus = addRecordViewModel.incomeRemarkInputState.focus.collectAsState()

    if (imePaddingBottomValue.value > 0.dp && remarkinputFocus.value) {
        scope.launch {
            colScroll.scrollTo(1000)
        }
    }
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(bottom = if (remarkinputFocus.value) imePaddingBottomValue.value else 0.dp)
            .verticalScroll(colScroll),
        verticalArrangement = Arrangement.Top,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        //这个是占位置的，把HorizontalPager往下挤，刚好形成 输入框嵌入背景的效果
        MySpacer(
            modifier = Modifier
                .height(topbarAndStatusBarHeight.dp)
                .background(Color.Red)
        )
        //金额输入框
        IncomeInput()
        //图标列表
        IncomeIconsList()
        //备注
        IncomeRemark(

            placeClick = placeClick
        )
        //保存按钮
        IncomeSaveBtn(
            enabled = true,
            imageVector = Icons.Rounded.Save
        )
    }
}


